package cn.itcast.controller;

import cn.itcast.Service.TeacherService;
import cn.itcast.common.PageBean;
import cn.itcast.common.R;
import cn.itcast.domain.dto.PageDTO;
import cn.itcast.domain.dto.TeacherDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zsw
 * @Date: 2024/1/18 16:41
 */

@RestController
@RequestMapping("/teacher")
@CrossOrigin
public class TeacherController {

    @Autowired
    private TeacherService teacherService;



    @PostMapping("/addTeacher")
    public R addTeacher(@RequestBody TeacherDTO teacher){
        int i = teacherService.addTeacher(teacher);
        if (i >= 1){
            return R.success();
        }
       return R.error("新增失败");
    }

    @DeleteMapping ("/deleteTeacherById/{id}")
    public R deleteTeacherById(@PathVariable("id") Integer teacherId){
        int i = teacherService.deleteTeacherById(teacherId);
        if (i >= 1){
            return R.success();
        }
        return R.error("新增失败");
    }

    @PostMapping("/updateTeacher")
    public R updateTeacher(TeacherDTO teacherDTO){
        int i = teacherService.updateTeacher(teacherDTO);
        if (i >= 1){
            return R.success();
        }
        return R.error("更新失败");
    }

    @GetMapping("/getTeacherByPage")
    public R getTeacherByPage(PageDTO pageDTO){
        PageBean teacherList = teacherService.getTeacherList(pageDTO);
        return R.success(teacherList);
    }
}
